let nums = [-1,0,3,5,9,12]
let target = 9
var search = function(nums, target) {
    let left = 0; 
    let right = nums.length-1;
    while(left<=right){
        const middle = Math.floor((right-left)/2)+left
        const num = nums[middle]
        if(num<target){
            left = middle + 1
        }else if(num>target){
            right = middle -1
        }else{
            return middle
        }
    }
    return -1
};
let a = search(nums,target);
console.log(a);